package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.swing.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.CaseComplaintType;
import com.ktgj.customer.service.ICaseComplaintTypeService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 投诉工单_投诉大类Controller
 * 
 * @author ruoyi
 * @date 2022-05-27
 */
@RestController
@RequestMapping("/laintType")
public class CaseComplaintTypeController extends BaseController
{
    @Autowired
    private ICaseComplaintTypeService caseComplaintTypeService;

    /**
     * 查询投诉工单_投诉大类列表
     */
    @PreAuthorize(hasPermi = "system:type:list")
    @GetMapping("/list")
    public TableDataInfo list(CaseComplaintType caseComplaintType)
    {
        startPage();
        List<CaseComplaintType> list = caseComplaintTypeService.selectCaseComplaintTypeList(caseComplaintType);
        return getDataTable(list);
    }

    /**
     * 导出投诉工单_投诉大类列表
     */
    @PreAuthorize(hasPermi = "system:type:export")
    @Log(title = "投诉工单_投诉大类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseComplaintType caseComplaintType) throws IOException
    {
        List<CaseComplaintType> list = caseComplaintTypeService.selectCaseComplaintTypeList(caseComplaintType);
        ExcelUtil<CaseComplaintType> util = new ExcelUtil<CaseComplaintType>(CaseComplaintType.class);
        util.exportExcel(response, list, "投诉工单_投诉大类数据");
    }

    /**
     * 获取投诉工单_投诉大类详细信息
     */
    @PreAuthorize(hasPermi = "system:type:query")
    @GetMapping(value = "/{complaintTypeId}")
    public AjaxResult getInfo(@PathVariable("complaintTypeId") Long complaintTypeId)
    {
        return AjaxResult.success(caseComplaintTypeService.selectCaseComplaintTypeById(complaintTypeId));
    }

    /**
     * 新增投诉工单_投诉大类
     */
    @PreAuthorize(hasPermi = "system:type:add")
    @Log(title = "投诉工单_投诉大类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseComplaintType caseComplaintType)
    {
        return toAjax(caseComplaintTypeService.insertCaseComplaintType(caseComplaintType));
    }

    /**
     * 修改投诉工单_投诉大类
     */
    @PreAuthorize(hasPermi = "system:type:edit")
    @Log(title = "投诉工单_投诉大类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaseComplaintType caseComplaintType)
    {
        return toAjax(caseComplaintTypeService.updateCaseComplaintType(caseComplaintType));
    }

    /**
     * 删除投诉工单_投诉大类
     */
    @PreAuthorize(hasPermi = "system:type:remove")
    @Log(title = "投诉工单_投诉大类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{complaintTypeIds}")
    public AjaxResult remove(@PathVariable Long[] complaintTypeIds)
    {
        return toAjax(caseComplaintTypeService.deleteCaseComplaintTypeByIds(complaintTypeIds));
    }
    @PostMapping("/selectTypeList")
    public AjaxResult selectTypeList(){
        List<CaseComplaintType>list=caseComplaintTypeService.selectTypeList();
        if(list.size()>0){
            return AjaxResult.success(list);
        }else {
            return  AjaxResult.success("没有相关数据");
        }
    }
}
